#include "openglContext.h"
#include <iostream>
using namespace std;

void openglContextMaya::dcInitialize()
{
	oldHDC = wglGetCurrentDC();
	if ( !oldHDC )
	{
		cout<<"error happens in wglGetCurrentDC"<<endl;
	}

	newHDC = CreateCompatibleDC(oldHDC);
	if (! newHDC)
	{
		cout<<"error happens in CreateCompatibleDC"<<endl;
	}
	openglSetPixelFormat();

	oldHRC = wglGetCurrentContext();
	if ( ! oldHRC)
	{
		cout<<"error happens in wglGetCurrentContext"<<endl;
	}
	newHRC = wglCreateContext(newHDC);
	if ( ! newHRC)
	{
		cout<<"error happens in wglCreateContext"<<endl;
	}

	wglMakeCurrent(newHDC, newHRC);

}

void openglContextMaya::openglSetPixelFormat()
{
	PIXELFORMATDESCRIPTOR openglPFD;
	ZeroMemory( &openglPFD, sizeof(openglPFD));
	openglPFD.nSize = sizeof(openglPFD);
	openglPFD.nVersion = 1;
	openglPFD.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
		PFD_DOUBLEBUFFER;
	openglPFD.iPixelType = PFD_TYPE_RGBA;
	openglPFD.cColorBits = 24;
	openglPFD.cDepthBits = 16;
	openglPFD.iLayerType = PFD_MAIN_PLANE;
	int openglFormat = ChoosePixelFormat( newHDC, &openglPFD );
	SetPixelFormat( newHDC, openglFormat, &openglPFD );

}